package com.example.liyun.joy.news;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

public class TabViewPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> tabListFragment;
    private List<String> tabListTitles;

    /**
     * 显示段子模块调用此方法赋值
     * @param tabListFragment
     */
    public void setTabListFragment(List<Fragment> tabListFragment){
        this.tabListFragment = tabListFragment;
        notifyDataSetChanged();
    }

    /**
     * 显示咨询模块，调用此方法赋值
     * @param tabListFragment
     * @param tabListTitles
     */
    public void setTabListFragmentandtab(List<Fragment> tabListFragment,List<String> tabListTitles) {
        this.tabListFragment = tabListFragment;
        this.tabListTitles=tabListTitles;
        notifyDataSetChanged();
    }

    public TabViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    /**
     * 返回fragment
     * @param i fragment下标
     * @return
     */
    @Override
    public Fragment getItem(int i) {
        return tabListFragment.get(i);
    }

    /**
     * 获得Fragment个数
     * @return
     */
    @Override
    public int getCount() {
        return tabListFragment!=null?tabListFragment.size():0;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return tabListTitles.get(position);
    }
}
